﻿Imports System.Data

Public Class FormActividadesListado

    Private Sub FormActividadesListado_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dgActividades.AutoGenerateColumns = False
        CargarActividades()
        llenarcmbsector()
    End Sub
    Dim classController As New Class_RC_Controller.rc_Mantenimiento()

    Private m_frmActividades As FrmActividades
    Public Property frmActividades() As FrmActividades
        Get
            Return m_frmActividades
        End Get
        Set(ByVal value As FrmActividades)
            m_frmActividades = value
        End Set
    End Property

    Private Sub CargarActividades()
        Dim CodSector As Integer
        If cbxSector.Checked Then
            CodSector = cmbsector.SelectedValue
        End If
        Dim dt As New DataTable
        dt = classController.get_Actividad_All(oiml.dbConn, 0, txtDescripcion.Text, CodSector)
        dgActividades.DataSource = dt
    End Sub
    Private Sub llenarcmbsector()
        Dim dsTipo As New DataTable
        dstipo = classController.get_Sector(oiml.dbConn)
        If Not dsTipo Is Nothing Then
            If dsTipo.Rows.Count > 0 Then
                cmbsector.DataSource = dsTipo
                cmbsector.DisplayMember = "DescSector"
                cmbsector.ValueMember = "CodSector"
            End If
        End If
    End Sub
    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        Me.Close()

    End Sub

    Private Sub btnEditar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditar.Click
        Try
            If dgActividades.SelectedRows.Count > 0 Then
                Dim CodActividad As New Integer
                CodActividad = dgActividades.SelectedRows(0).Cells(0).Value

                If frmActividades Is Nothing Then
                    frmActividades = New FrmActividades
                    frmActividades.CodActividad = CodActividad
                    'If frmServicios.ShowDialog() = Windows.Forms.DialogResult.OK Then
                    frmActividades.ShowDialog()
                    CargarActividades()
                    FrmTipoProd.Dispose()
                    FrmTipoProd = Nothing
                    'End If
                Else
                    frmActividades.CodActividad = CodActividad
                    frmActividades.ShowDialog()
                End If

            End If

        Catch ex As Exception
            MessageBox.Show("Error: " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try

    End Sub

    Private Sub btnBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscar.Click

        CargarActividades()

    End Sub

    Private Sub txtDescripcion_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtDescripcion.KeyDown
        If e.KeyCode = Keys.Enter Then
            CargarActividades ()

        End If
    End Sub

    Private Sub dgActividades_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgActividades.DoubleClick
        btnEditar_Click(sender, e)
    End Sub

    Private Sub dgActividades_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dgActividades.KeyDown
        If e.KeyCode = Keys.Enter Then
            btnEditar_Click(sender, e)
        End If

    End Sub

    'Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint

    'End Sub


    Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint

    End Sub

    Private Sub btnNuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNuevo.Click
        '    If frmciudad Is Nothing Then
        frmActividades = New FrmActividades()
        frmActividades.ShowDialog()
        CargarActividades()
    End Sub
End Class